package com.collection;

import java.util.LinkedList;

/**
 * @Author WaveHi
 * @Date 15/8/2021 上午 11:26
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description LinkedList的使用
 */
public class TestLinkedList {

    public static void main(String[] args) {

        //获取LinkedList集合对象
        LinkedList<Person> persons = new LinkedList<>();

        //向集合添加数据
        persons.add(new Person("Tom",23));
        persons.add(new Person("John",12));
        persons.add(new Person("Marry",17));
        persons.addFirst(new Person("Betty",5));
        persons.push(new Person("LiHua",53));

        //获取集合数据
        System.out.println("The data of index 0 in the collection is: " + persons.get(0));
        System.out.println(persons);
        System.out.println("The data in the collection is :" + persons.pop());
        System.out.println("persons is :" + persons);

        //修改集合数据
        persons.set(0,new Person("San",15));
        System.out.println("persons is :" + persons);

        //删除集合数据
        persons.remove(0);
        System.out.println("Persons is :" + persons);

    }

}
